package com.tuanzi.service.impl;

import com.tuanzi.ResultVo.ResultVO;
import com.tuanzi.dao.UserMapper;
import com.tuanzi.service.PwdService;
import com.tuanzi.utils.Status;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * @author tuanzi
 * @version 1.0
 * @date 2022/3/31 13:35
 */

@Service
public class PwdServiceImpl implements PwdService {

    @Resource
    private UserMapper userMapper;

    /**
     * 更新密码 通过id和新密码
     *
     * 也需要添加事务
     */
    @Transactional
    @Override
    public ResultVO updatePwd(Integer id, String pwd) {

        ResultVO vo;

        if (userMapper.updatePwd(id, pwd) != 0) {
            vo = new ResultVO(Status.CHANGESUCCESS,userMapper.selectById(id));
        }else {
            vo = new ResultVO(Status.CHANGEFAILED,null);
        }

        return vo;
    }

}
